package com.woniuxy.microstockserver.mapper;

import com.woniuxy.microstockserver.bean.OutStockGoodsDetailBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 赵雄伟
 * 入库单入库商品详情 Mapper
 */
@Mapper
public interface OutStockGoodsDetailMapper {

    /**
     * 新增出库单的新增出库商品
     * @param osId
     * @param outStockGoodsDetailBeans
     */
    @Insert("<script>" +
            "insert into t_outstock_goodsdetails_info (fk_goods_id,os_goods_remarks,fk_os_id,delete_status,os_goods_amount) values "+
            "<foreach collection='list' item='goods'  separator=','>"+
            "(#{goods.goodsId},#{goods.osGoodsRemarks},#{osId},#{goods.deleteStatus},#{goods.osGoodsAmount})"+
            "</foreach>"+
            "</script>")
    void saveOutStockGoodsDetailBean(@Param("osId") Long osId, @Param("list") List<OutStockGoodsDetailBean> outStockGoodsDetailBeans);

    /**
     * 根据出库单外键id查询出库单详情
     */
    @Results({
            @Result(id = true,property = "id",column = "id",javaType = Long.class),
            @Result(property = "goodsId",column = "fk_goods_id",javaType = Long.class),
            @Result(property = "osGoodsRemarks",column = "os_goods_remarks",javaType = String.class),
            @Result(property = "osId",column = "fk_os_id",javaType = Long.class),
            @Result(property = "deleteStatus",column = "delete_status",javaType = Byte.class),
            @Result(property = "osGoodsAmount",column = "os_goods_amount",javaType = Integer.class)
    })
    @Select("select * from t_outstock_goodsdetails_info where fk_os_id = #{osId}")
    List<OutStockGoodsDetailBean> findOutStockAndGoodsDetail(@Param("osId") Long id);

    /**
     * 根据出库单外键id，删除出库单商品信息，主要用于修改出库单
     * @param id
     */
    @Delete("delete from t_outstock_goodsdetails_info where fk_os_id = #{osId}")
    void deleteByOsId(@Param("osId") Long id);
}
